package com.example.demo.lc;

import java.util.Arrays;

/**
 * @Description 拼车
 * @Author wzh
 * @Date 2021/11/16 11:06 上午
 * @Version 1.0
 */
public class Leetcode1094 {
    public static void main(String[] args) {
        int[][] trips = {{2,1,5},{3,3,7}};
        int capacity = 4;
        System.out.println(carPooling(trips,capacity));
    }

    public static boolean carPooling(int[][] trips, int capacity) {
        int n = 1000;
        int[] diff = new int[n];
        int[] caps = new int[n];
        int max = 0;
        for (int i = 0; i < trips.length; i++) {
            int[] trip = trips[i];
            max = Math.max(max,trip[1]);
            diff[trip[1]] += trip[0];
            diff[trip[2]] -= trip[0];
        }
        System.out.println(Arrays.toString(diff));
        System.out.println("===================");
        if (diff[0] > capacity) return false;
        caps[0] = diff[0];
        for (int i = 1; i <= max; i++) {
            caps[i] = caps[i-1] + diff[i];
            System.out.println(Arrays.toString(caps));
            if (caps[i] > capacity) return false;
        }
        return true;
    }
}
